<template>
  <div class="overview-center-wrap">
    <!-- 状态计时器 -->
    <div class="state-timing" :class="'fireType-' + fireType">
      <p>
        {{ connectingTimeText
                }}<span class="time">{{ connectingTime }}</span>
      </p>
    </div>
    <!-- 设备图 -->
    <div class="device-canvas">
      <!-- 设备信息 -->
      <div class="device-img-wrap">
        <el-image v-if="baseInfo.fcfId" style="margin-top: 40px;width: 250px; height: 250px;" :src="
                        baseInfo.icon
                            ? JSON.parse(baseInfo.icon).detailIcon
                            : ''
                    " fit="contain">
          <!-- 暂无图片 -->
          <div slot="error" class="image-slot">
            <div class="no-image2"></div>
          </div>
        </el-image>
        <p class="device-name">{{ baseInfo.fcfName }}</p>
      </div>
      <!-- 球 -->
      <div class="ball-one"></div>
      <div class="ball-two"></div>
      <div class="ball-three"></div>
      <!-- 底座 -->
      <!-- <div class="ellipse"></div> -->
      <div class="ellipse-one"></div>
      <div class="ellipse-two"></div>
      <div class="ellipse-three"></div>
    </div>
    <!-- 设备装填属性 -->
    <div class="device-attributes-wrap">
      <ul class="device-attributes-list">
        <!-- 关联设备 -->
        <template v-if="
                        baseInfo.relateFcfList &&
                            baseInfo.relateFcfList.length > 0
                    ">
          <li v-for="item in baseInfo.relateFcfList" class="device-attributes-item" :key="item.fcfId">
            <el-image style="width: 50px; height: 50px;" :src="item.statusPic" fit="contain"></el-image>
            <p>关联{{ item.fcfName }}</p>
            <p>{{ item.statusAlias }}</p>
          </li>
        </template>
        <template v-if="baseInfo.analogList && baseInfo.analogList.length > 0">
          <!-- 模拟量 -->
          <li v-for="item in baseInfo.analogList" class="device-attributes-item" :key="item.id">
            <p class="type-name">当前{{ item.dataTypeName }}</p>
            <p class="analog-value" :class="'analog-value-' + item.fireTType">
              {{ item.analogValue }}
              <span>{{ item.analogUnits }}</span>
            </p>
          </li>
        </template>
        <!-- 视频分析图片 -->
        <li v-if="baseInfo.isVideoAnalysis && currentUrl" class="device-attributes-item">
          <el-image class="video-analysis-img" :src="currentUrl + '?imageView2/2/w/200/h/80/q/75'" fit="contain" @click="onPreview" :preview-src-list="srcList"></el-image>
        </li>
      </ul>
    </div>
    <trans-ai-pic v-if="showCanvasPreview" :transAiPicToBase64="transAiPicToBase64" :drawData="baseInfo" />
  </div>
</template>
<script>
var day = '0' // 天
var hour = '00' // 时
var minus = '00' // 分
var seconds = '00' // 秒
var t1 = null

import TransAiPic from '@/components/TransAiPic' // 视频分析图片转base64

export default {
  props: {
    deviceInfo: {
      default() {
        return false
      },
    },
  },
  components: {
    TransAiPic,
  },
  data() {
    return {
      fireType: '',
      connectingTimeText: '',
      connectingTime: '0天00小时00分钟00秒', // 状态持续时间
      baseInfo: this.deviceInfo || {},
      /* 图片预览相关的变量 */
      currentUrl: '',
      srcList: [],
      showCanvasPreview: false, // 图片对象转base64的组件
    }
  },
  created() {},
  methods: {
    mapConnectingTimeText() {
      let Map = {
        10: '报警已持续',
        20: '故障已持续',
        30: '屏蔽已持续',
        40: '联动已持续',
        0: '持续正常',
      }
      this.connectingTimeText = Map[this.fireType]
    },
    // 开始计时
    startTiming() {
      let that = this
      // 参数初始化
      t1 = null

      t1 = setInterval(() => {
        that.runTime()
      }, 1000)
    },
    // 计时器算法
    runTime() {
      let that = this
      //毕业时间
      let startTime = new Date(that.baseInfo.recordsInfoCreateTime)
      //获取当前时间
      let today = new Date()
      let timeold = today.getTime() - startTime.getTime() //总豪秒数
      let secondsold = Math.floor(timeold / 1000) //总秒数
      let e_daysold = timeold / (24 * 60 * 60 * 1000)
      day = Math.floor(e_daysold) //相差天数
      let e_hrsold = (e_daysold - day) * 24
      hour = Math.floor(e_hrsold) //相差小时数
      let e_minsold = (e_hrsold - hour) * 60
      minus = Math.floor(e_minsold) //相差分钟数
      seconds = Math.floor((e_minsold - minus) * 60) //相差秒数

      if (hour < 10) {
        hour = '0' + hour
      }

      if (minus < 10) {
        minus = '0' + minus
      }

      if (seconds < 10) {
        seconds = '0' + seconds
      }

      that.connectingTime = day + '天' + hour + '小时' + minus + '分钟' + seconds + '秒'
    },
    onPreview() {
      this.$Ctl.loading(1, 10000)
      this.showCanvasPreview = true
      this.srcList = []
    },
    transAiPicToBase64(base64Data) {
      this.showCanvasPreview = false
      this.$set(this.srcList, 0, base64Data)
      this.$Ctl.loading(0)
    },
  },
  watch: {
    deviceInfo(val, oldVal) {
      let that = this
      if (val) {
        that.baseInfo = val
        that.fireType = that.baseInfo.fireTType
        if (that.baseInfo.resultRegion) {
          that.currentUrl = JSON.parse(that.baseInfo.resultRegion).imageInfo.pic
        } else {
          that.currentUrl = ''
        }
        that.mapConnectingTimeText()
        that.startTiming()
        that.$Ctl.loading(0)
      }
    },
  },
}
</script>
<style lang="scss">
.overview-center-wrap {
  width: 100%;
  height: 100%;
  background: url(../../../../../assets/images/detailPage/device-bg.png)
        center center no-repeat;
  background-size: cover;
  .state-timing {
    width: 100%;
    height: 90px;
    text-align: center;
    font-size: 26px;
    font-weight: 400;
    background-size: contain;
    &.fireType-10 {
      background: url(../../../../../assets/images/detailPage/bj-state-timing.png)
                center center no-repeat;
      color: #bd2d4c;
    }
    &.fireType-20 {
      background: url(../../../../../assets/images/detailPage/gz-state-timing.png)
                center center no-repeat;
      color: #f0a045;
    }
    &.fireType-30 {
      background: url(../../../../../assets/images/detailPage/pb-state-timing.png)
                center center no-repeat;
      color: #dadada;
    }
    &.fireType-40 {
      background: url(../../../../../assets/images/detailPage/ld-state-timing.png)
                center center no-repeat;
      color: #286ed7;
    }
    &.fireType-0 {
      background: url(../../../../../assets/images/detailPage/zc-state-timing.png)
                center center no-repeat;
      color: #64a98b;
    }
    p {
      display: flex;
      justify-content: center;
      line-height: 80px;
      .time {
        margin-left: 20px;
        font-family: 'DigitaldreamFat';
        font-size: 22px;
      }
    }
  }
  .device-canvas {
    position: relative;
    width: 100%;
    height: 700px;
    background: url(../../../../../assets/images/detailPage/device-main-canves.png)
            center center no-repeat;
    background-size: contain;
    .device-img-wrap {
      position: absolute;
      top: 50%;
      left: 50%;
      top: 80px;
      margin-left: -200px;
      width: 400px;
      height: 400px;
      text-align: center;
      .device-name {
        font-size: 36px;
        line-height: 60px;
        color: #fff;
        font-weight: bold;
        z-index: 10;
      }
    }
    .ball-one,
    .ball-two,
    .ball-three,
    .ellipse-one,
    .ellipse-two,
    .ellipse-three {
      position: absolute;
      top: 50%;
      left: 50%;
      border-radius: 50%;
      border: 1px solid #23acfb;
    }
    .ball-one,
    .ball-two,
    .ball-three {
      top: 71px;
      margin-left: -211px;
      // border:1 solid rgba(35,172,251,1);
      width: 420px;
      height: 420px;
      // background:rgba(35,172,251,1);
      animation: light-wave1 3s infinite;
      // transform: scale(0.77);
      box-sizing: content-box;
    }
    .ball-one {
      // background: radial-gradient(rgba(35,172,251,.1),rgba(35,172,251,.2),rgba(26,175,253,1));
      // animation: light-wave 2s infinite;
    }
    .ball-two {
      animation-delay: 1s;
    }
    .ball-three {
      animation-delay: 2s;
    }
    // .ellipse{
    //     position: absolute;
    //     top: 50%;
    //     left: 50%;
    //     margin-top: 88px;
    //     margin-left: -274px;
    //     width:548px;
    //     height:110px;
    //     border:solid 1px #23acfb;
    //     // background:rgba(55,169,251,1);
    //     background: radial-gradient(rgba(35,172,251,.1),rgba(35,172,251,.2),rgba(26,175,253,1));
    //     border-radius: 50%;
    //     transform: rotateX(35deg);
    //     &::after{
    //         content: '';
    //         display: inline-block;
    //         width: 548px;
    //         height: 110px;
    //         position: relative;
    //         background:rgba(55,169,251,.3);
    //         top: 46%;
    //         border-bottom-left-radius: 50%;
    //         border-bottom-right-radius: 50%;
    //     }
    // }
    .ellipse-one,
    .ellipse-two,
    .ellipse-three {
      margin-top: 62px;
      margin-left: -460px;
      width: 920px;
      height: 315px;
      transform: rotateX(35deg);
      background: radial-gradient(
        rgba(35, 172, 251, 0.1),
        rgba(35, 172, 251, 0.2),
        rgba(26, 175, 253, 1)
      );
      opacity: 0;
      animation: light-wave-rotate 2.1s infinite;
    }
    .ellipse-one {
      // margin-top: 68px;
      // margin-left: -359px;
      // width: 718px;
      // height: 230px;
      // transform: rotateX(35deg);
      // background: radial-gradient(rgba(35,172,251,.1),rgba(35,172,251,.2),rgba(26,175,253,1));
    }
    .ellipse-two {
      // margin-top: 62px;
      // margin-left: -460px;
      // width: 920px;
      // height: 315px;
      animation-delay: 0.7s;
      // transform: rotateX(35deg);
      // background: radial-gradient(rgba(35,172,251,.1),rgba(35,172,251,.2),rgba(26,175,253,1));
    }
    .ellipse-three {
      animation-delay: 1.4s;
    }
  }
  .device-attributes-wrap {
    margin-top: 10px;
    .device-attributes-list {
      display: flex;
      padding: 0 10px;
      .device-attributes-item {
        margin: 0 10px;
        padding: 10px 0;
        width: 260px;
        height: 100px;
        line-height: 40px;
        background: rgba(81, 166, 250, 0.1);
        border-radius: 5px;
        font-size: 20px;
        text-align: center;
        .type-name {
          color: #a3bedd;
        }
        .analog-value {
          color: #49b9ad;
          font-weight: 400;
          &.analog-value-10 {
            color: #bd2d4c;
          }
          &.analog-value-20 {
            color: #f0a045;
          }
        }
        .video-analysis-img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
}
</style>
